function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
% function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T             [#temp variables by 1]     double   vector of temporary terms to be filled by function
%   y             [#dynamic variables by 1]  double   vector of endogenous variables in the order stored
%                                                     in M_.lead_lag_incidence; see the Manual
%   x             [nperiods by M_.exo_nbr]   double   matrix of exogenous variables (in declaration order)
%                                                     for all simulation periods
%   steady_state  [M_.endo_nbr by 1]         double   vector of steady state values
%   params        [M_.param_nbr by 1]        double   vector of parameter values in declaration order
%   it_           scalar                     double   time period for exogenous variables for which
%                                                     to evaluate the model
%   T_flag        boolean                    boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = model_6_IRFs.dynamic_resid_tt(T, y, x, params, steady_state, it_);
end
residual = zeros(46, 1);
lhs = y(43);
rhs = T(1);
residual(1) = lhs - rhs;
lhs = y(45);
rhs = T(2);
residual(2) = lhs - rhs;
lhs = y(44);
rhs = T(3);
residual(3) = lhs - rhs;
lhs = y(46);
rhs = T(4);
residual(4) = lhs - rhs;
lhs = 1/y(40);
rhs = T(5)*T(6)+params(1)*(1-params(8))/y(58);
residual(5) = lhs - rhs;
lhs = 1/y(40);
rhs = T(7)*(1+y(59));
residual(6) = lhs - rhs;
lhs = y(40);
rhs = params(3)*T(8)^((params(3)-1)/params(3));
residual(7) = lhs - rhs;
lhs = y(26)^(-params(2));
rhs = params(6)/(1-params(5))/y(40);
residual(8) = lhs - rhs;
lhs = y(40)*y(48)/params(6);
rhs = y(2)*T(9)-y(36)*y(42);
residual(9) = lhs - rhs;
lhs = y(17);
rhs = 0.5*(1+erf(T(10)));
residual(10) = lhs - rhs;
lhs = y(29);
rhs = T(11);
residual(11) = lhs - rhs;
lhs = y(36)*y(17)*(1+y(30));
rhs = y(1)*y(3)*(1+y(6));
residual(12) = lhs - rhs;
lhs = 1+y(4);
rhs = (1+y(30))*(1+y(41));
residual(13) = lhs - rhs;
lhs = y(42);
rhs = y(44)*params(9)*params(10)*y(24)*(1-params(4));
residual(14) = lhs - rhs;
lhs = y(24)*y(47)*(1-params(4));
rhs = y(36)/y(2)+params(12)*(1-params(8))-(1-params(8))*(1-y(5));
residual(15) = lhs - rhs;
lhs = y(39);
rhs = y(2)*params(10)*y(17)*T(12);
residual(16) = lhs - rhs;
lhs = y(38);
rhs = y(2)*params(10)*y(17)*T(13);
residual(17) = lhs - rhs;
lhs = y(31)*(y(39)+y(38)+y(27));
rhs = y(39)+y(38);
residual(18) = lhs - rhs;
lhs = (y(39)+y(38))*y(32);
rhs = y(39);
residual(19) = lhs - rhs;
lhs = y(25);
rhs = y(2)*params(52)+y(43)*y(2)*params(10)*y(17)+y(46)*y(2)*params(10)*y(17);
residual(20) = lhs - rhs;
lhs = y(28);
rhs = y(26)+y(53)+y(35)-y(2)*(1-params(8));
residual(21) = lhs - rhs;
lhs = y(28);
rhs = y(24)*y(25)/(1-params(3));
residual(22) = lhs - rhs;
lhs = y(27);
rhs = y(35)-y(2)*(1-params(8));
residual(23) = lhs - rhs;
lhs = y(37);
rhs = y(25)*T(15);
residual(24) = lhs - rhs;
lhs = T(17)*T(18)*T(19);
rhs = y(28);
residual(25) = lhs - rhs;
lhs = y(34);
rhs = T(17);
residual(26) = lhs - rhs;
lhs = y(49);
rhs = T(20);
residual(27) = lhs - rhs;
lhs = y(50);
rhs = T(21);
residual(28) = lhs - rhs;
lhs = y(20);
rhs = log(y(40))-log((steady_state(32)));
residual(29) = lhs - rhs;
lhs = y(16);
rhs = log(1+y(30))-log(1+(steady_state(22)));
residual(30) = lhs - rhs;
lhs = y(22);
rhs = y(42)-(steady_state(34));
residual(31) = lhs - rhs;
lhs = y(14);
rhs = log(y(31))-log((steady_state(23)));
residual(32) = lhs - rhs;
lhs = y(15);
rhs = log(y(32))-log((steady_state(24)));
residual(33) = lhs - rhs;
lhs = y(23);
rhs = log(y(33))-log((steady_state(25)));
residual(34) = lhs - rhs;
lhs = y(13);
rhs = log(y(34))-log((steady_state(26)));
residual(35) = lhs - rhs;
lhs = y(21);
rhs = log(y(36))-log((steady_state(28)));
residual(36) = lhs - rhs;
lhs = y(9);
rhs = log(y(28)+y(40)*y(29)*params(15)-y(53))-log((steady_state(20)+steady_state(32)*steady_state(21)*params(15)-steady_state(45)));
residual(37) = lhs - rhs;
lhs = y(11);
rhs = log(y(27))-log((steady_state(19)));
residual(38) = lhs - rhs;
lhs = y(10);
rhs = log(y(26)+y(40)*y(29)*params(15))-log((steady_state(18)+steady_state(32)*steady_state(21)*params(15)));
residual(39) = lhs - rhs;
lhs = y(12);
rhs = log(y(29)+y(37))-log((steady_state(21)+steady_state(29)));
residual(40) = lhs - rhs;
lhs = y(19);
rhs = log(y(49))-log((steady_state(41)));
residual(41) = lhs - rhs;
lhs = y(18);
rhs = log(y(50))-log((steady_state(42)));
residual(42) = lhs - rhs;
lhs = log(y(51))-log(params(11));
rhs = params(22)*(log(y(5))-log(params(11)))+params(26)*x(it_, 1);
residual(43) = lhs - rhs;
lhs = log(1+y(52))-log(1+params(7));
rhs = params(24)*(log(1+y(6))-log(1+params(7)))-params(28)*x(it_, 3);
residual(44) = lhs - rhs;
lhs = log(y(54))-log(params(35));
rhs = params(23)*(log(y(8))-log(params(35)))+params(27)*x(it_, 2);
residual(45) = lhs - rhs;
lhs = log(y(53))-log(params(34));
rhs = params(25)*(log(y(7))-log(params(34)))+params(29)*x(it_, 4);
residual(46) = lhs - rhs;

end
